package softserve.vgolosh;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import softserve.vgolosh.tmn.TMN;
import softserve.vgolosh.tmn.TMNSearchResults;
import softserve.vgolosh.tmn.TMNUtilities;
import softserve.vgolosh.utils.FileUtil;
import softserve.vgolosh.utils.PropertiesHelper;
import softserve.vgolosh.utils.PropertyNotFoundException;

public class MainClass {
	private static String NOTEPAD_LOCATION = "c:\\Program Files\\Notepad++\\";
	private static String UI_SEARCH_RESULT_FILE = "UIsearchResults.txt";
	public static String UI_SEARCH_DIR = "d:\\svnwork\\customers\\trunk\\working\\";
	static {
		if (PropertiesHelper.isInitialised()) {
			try {
				UI_SEARCH_DIR = PropertiesHelper.getProperty("UI_SEARCH_DIR");
			} catch (PropertyNotFoundException e) {
				System.out.println(e);
				System.out.println("using default value " + UI_SEARCH_DIR);
			}
			try {
				UI_SEARCH_RESULT_FILE = PropertiesHelper
						.getProperty("UI_SEARCH_RESULT_FILE");
			} catch (PropertyNotFoundException e) {
				System.out.println(e);
				System.out.println("using default value "
						+ UI_SEARCH_RESULT_FILE);
			}
			try {
				NOTEPAD_LOCATION = PropertiesHelper
						.getProperty("NOTEPAD_LOCATION");
			} catch (PropertyNotFoundException e) {
				System.out.println(e);
				System.out.println("using default value " + NOTEPAD_LOCATION);
			}
		}
	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("Please enter the version to search");
		String answer = scanner.nextLine();
		List<String> clients = FileUtil.getClientDirectories(UI_SEARCH_DIR);
		TMN tmn = new TMN("Searched version", "bundleConfiguration.xml", answer);
		List<TMN> tmnList = new ArrayList<TMN>();
		tmnList.add(tmn);
		TMNSearchResults results = TMNUtilities.searchUIResults(UI_SEARCH_DIR, clients,
				tmnList);
		FileUtil.writeListToFile(results.getClientsFromResults(),
				UI_SEARCH_RESULT_FILE);
		System.out.println("Done");
		scanner.nextLine();
	}
}
